package com.hy.mydesktop.client.component.factory;

import com.extjs.gxt.ui.client.widget.form.FileUploadField;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
import com.test.client.component.meta.FileUploadModelEnum;

/**
 * 
 * <ul>
 * <li>开发作者：冬超</li>
 * <li>设计日期：2010-8-29；时间：下午04:40:26</li>
 * <li>类型名称：FileUploadFactory</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class FileUploadFactory {
	public static FileUploadField createPagingToolBar(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {
		
		return configureFileUploadField(gxtComponentMetaNodeModel);

	}

	/**
	 * 
	 * 
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	private static FileUploadField configureFileUploadField(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {
		

		FileUploadField fileUpload = createDefaultFileUploadField();
	
		fileUpload = AbstractComponetFactory.configureAbstractComponet(fileUpload, gxtComponentMetaNodeModel);

		
		if (gxtComponentMetaNodeModel.get(FileUploadModelEnum.HIGHT.name()
				.toLowerCase()) != null) {
			Integer height = (Integer) gxtComponentMetaNodeModel
					.get(FileUploadModelEnum.HIGHT.name().toLowerCase());
			fileUpload.setHeight((int)height);

		}
		if (gxtComponentMetaNodeModel.get(FileUploadModelEnum.WIDTH
				.name().toLowerCase()) != null) {
			Integer width = (Integer) gxtComponentMetaNodeModel
					.get(FileUploadModelEnum.WIDTH.name().toLowerCase());
			fileUpload.setWidth((int)width);

		}
		if (gxtComponentMetaNodeModel.get(FileUploadModelEnum.BLANK
				.name().toLowerCase()) != null) {
			Boolean allowBlank = (Boolean) gxtComponentMetaNodeModel
					.get(FileUploadModelEnum.BLANK.name().toLowerCase());
			fileUpload.setAllowBlank((boolean)allowBlank);

		}
		if (gxtComponentMetaNodeModel.get(FileUploadModelEnum.LABEL
				.name().toLowerCase()) != null) {
			String fieldLabel = (String) gxtComponentMetaNodeModel
					.get(FileUploadModelEnum.LABEL.name().toLowerCase());
			fileUpload.setFieldLabel(fieldLabel);

		}
		if (gxtComponentMetaNodeModel.get(FileUploadModelEnum.NAME
				.name().toLowerCase()) != null) {
			String name = (String) gxtComponentMetaNodeModel
					.get(FileUploadModelEnum.NAME.name().toLowerCase());
			fileUpload.setName(name);

		}
		if (gxtComponentMetaNodeModel.get(FileUploadModelEnum.ICON
				.name().toLowerCase()) != null) {
			AbstractImagePrototype buttonIconStyle = (AbstractImagePrototype) gxtComponentMetaNodeModel
					.get(FileUploadModelEnum.ICON.name().toLowerCase());
			fileUpload.setButtonIcon(buttonIconStyle);

		}

		return fileUpload;
	}

	private static FileUploadField createDefaultFileUploadField() {

		FileUploadField fileUpload = new FileUploadField();
		return fileUpload;
	}
}
